/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
  if (nums.length === 0) return 0;
  let arr = [...new Set([...nums].sort((a, b) => a - b))]
  let flag = [];
  let lengthArr = [];
  for (let i = 0, j = i + 1; i < arr.length; i++, j++) {
    if (arr[j] - arr[i] === 1) {
      flag.push(arr[i]);
    } else {
      flag.push(arr[i]);
      lengthArr.push(flag.length);
      flag = [];
    }
  }
  return Math.max(...lengthArr);
};
let arr = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1];
console.log(longestConsecutive(arr)); // 9